﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.DAO;
using Com.CMS263.Util;

namespace Com.CMS263.BLL
{
    public class WorkerBLL : BaseBLL<Worker>
    {
        public Worker entity = new Worker();
        WorkerDAO dao = new WorkerDAO();
        public override Worker GetModel()
        {
            return entity;
        }
        /// <summary>
        /// 人员登录
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="upass"></param>
        /// <returns></returns>
        public Worker WorkLogin(string uname, string upass)
        {
            Worker worker = new Worker();
            worker = dao.Login(uname, upass);
            if (worker != null)
            {
                LoginLogBLL llbll = new LoginLogBLL();
                LoginLog ll = new LoginLog();
                ll.AddDate = DateTime.Now;
                ll.UserId = worker.Id;
                ll.UserIp = StringUtil.GetIP();
                llbll.entity = ll;
                llbll.Add();
                LoginCookie.SaveLoginInfo(new LoginInfo(worker.UserName, worker.Id));
                return worker;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 判断用户是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool isExist(string userName)
        {
            return dao.isExist(userName);
        }

        public IList<Worker> GetAllWorker()
        {
            return dao.GetItemList();
        }
        /// <summary>
        /// 根据角色查询用户信息
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public IList<Worker> GetItemListByRole(string roleID)
        {
            return dao.GetItemListByRole(roleID);
        }
        public IList<Worker> GetWorkerByPaging(int page, int pagesize)
        {
            return dao.GetWorkerByPaging(page, pagesize);
        }
        public int GetWorkerByPaging()
        {
            return dao.GetWorkerByPaging();
        }

        /// <summary>
        /// 查询全部用户信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Worker> GetAllWorker(int page, int pagesize)
        {
            return dao.GetAllWorker(page,pagesize);
        }

        /// <summary>
        /// 查询全部用户数量
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public int GetAllWorkerCount()
        {
            return dao.GetAllWorkerCount();
        }
    }
    
}
